/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bgIntlgn.client.entity.privilege;

import yuhuibear.poat.annotations.action.AutoGenerateValue;
import yuhuibear.poat.annotations.relation.Field;
import yuhuibear.poat.annotations.relation.Table;
import yuhuibear.poat.object.bean.Bean;

/**
 * 
 * @author yuhuibear
 */
@Table(name = "accounts", constrain = "")
public class Account implements Bean {

	@AutoGenerateValue(skipOnNull = true, sqlToGet = "select currval('accounts_id_seq')")
	@Field(name = "id", type = "bigserial", constrain = " primary key")
	private Long id;

	/**
	 * 账号角色
	 */
	@Field(name = "role", type = "char(40) ", constrain = " not null references roles(name)  on update cascade ")
	private String role;

	/**
	 * 帐号所有人
	 */
	@Field(name = "employee_id", type = "int8 ", constrain = " not null references employees(id)  on update cascade on delete cascade")
	private Long employeeId;

	/**
	 * 登录名
	 */
	@Field(name = "name", type = "varchar(40)", constrain = " not null unique")
	private String name;

	/**
	 * 密码
	 */
	@Field(name = "password", type = "varchar(250)", constrain = "not null")
	private String password;

	/**
	 * 登录计数器
	 */
	@Field(name = "log_cnt", type = "integer", constrain = " not null default 0")
	private Integer logCnt = 0;

	/**
	 * 账号是否启用
	 */
	@Field(name = "enable", type = "boolean", constrain = "default true")
	private boolean enable;

	public String toString() {
		return name + " ,own by " + employeeId + ", loged " + logCnt;
	}

	public int hashCode() {
		return id.intValue();
	}

	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		if (getClass() != obj.getClass()) { return false; }
		final Account other = (Account) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) { return false; }
		return true;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getLogCnt() {
		return logCnt;
	}

	public void setLogCnt(Integer logCnt) {
		if (logCnt != null) this.logCnt = logCnt;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Long getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(Long employeeId) {
		this.employeeId = employeeId;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role != null ? role.trim() : null;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

}
